/* -----------------------------------------------------------------------------
 * PROJECT    : lwf_common
 * FILE       : EncoderDecoder.java
 *
 * HISTORY:
 * Date          Author                        Description
 * ----------------------------------------------------------------------------- 
 * Mar 27, 2012  MyCodeTalks			       Created
 */

package net.lwf.encode;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;

import org.apache.log4j.Logger;

public class EncoderDecoder {

	private static final Logger logger = Logger.getLogger(net.lwf.encode.EncoderDecoder.class);
	
	private static final String ENCRYPTION_KEY = "UTF-8";
	
	public static String encodeString(String value) {
		String encoded = value;
		try {
			encoded = URLEncoder.encode(value, ENCRYPTION_KEY);
		} catch (UnsupportedEncodingException e) {
			logger.error("Exception while encoding :" + value + " : "+e.getMessage());
		}
		return encoded;
	}
	
	public static String decodeString(String value) {
		String decoded = value;
		try {
			decoded = URLDecoder.decode(value, ENCRYPTION_KEY);
		} catch (UnsupportedEncodingException e) {
			logger.error("Exception while decoding :" + value + " : "+e.getMessage());
		}
		return decoded;
	}

}
